﻿/*
 * Created by SharpDevelop.
 * User: hugo
 * Date: 2012/9/7
 * Time: 下午 09:25
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using NUnit.Framework;
using NCommon.Data;
using Microsoft.Practices.ServiceLocation;
using System.Linq;
using Rhino.Mocks;

namespace MyPetShop.Domain.Spec
{
	/// <summary>
	/// Description of Storage_CategoryRepository.
	/// </summary>
	[TestFixture]
	public class Storage_CategoryRepository
	{	
		[Test]
		public void Set_Delete_For_Category()
		{
			Category category = new Category()
			{
				Name = "Dogs"
			};
			
			Product product = new Product()
			{
				Name = "Lala",
				Description = "Black",
				Category = category				
			};
			
			MockRepository mocks = new MockRepository();
			IServiceLocator serviceLocator = mocks.StrictMock<IServiceLocator>();
			ServiceLocator.SetLocatorProvider(() => serviceLocator);
			
			var productRepository = new FakeRepository<Product>();
			productRepository.Add(product);
			
			var itemRepository = new FakeRepository<Item>();
			
			using(mocks.Record())
            {
				serviceLocator.Expect(s => s.GetInstance<IRepository<Product>>()).Return(productRepository).Repeat.Any();
                serviceLocator.Expect(s => s.GetInstance<IRepository<Item>>()).Return(itemRepository).Repeat.Any();
			}
			
			using(mocks.Playback())
			{
				category.Delete();
			}
			
			Assert.IsTrue(product.IsDelete);
		}
	}
}
